﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.ComponentModel;

namespace GU.WebERP.Core.Utils
{
    public class EnumHelper
    {
        public static string GetDescription(Type type, object value)
        {
            if (type == null || value == null)
            {
                throw new ArgumentNullException("EnumHelper.GetDescription(Type type, object value) 参数不能为空");
            }

            FieldInfo field = type.GetField(Enum.GetName(type, value));
            if (field != null)
            {
                object[] attribs = field.GetCustomAttributes(typeof(DescriptionAttribute), false);
                if (attribs != null && attribs.Length > 0)
                {
                    return ((DescriptionAttribute)attribs[0]).Description;
                }
            }
            return value.ToString();
        }
    }
}
